package cn.ruituo.adv8;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MyServer1 {
    public static void main(String[] args) {
        try {
            //服务器监听在8888端口
            ServerSocket st=new ServerSocket(8888);
            System.out.println("服务启动成功！");
            while (true){
                Socket socket = st.accept();//和客户端建立连接
                System.out.println(socket.getInetAddress()+","+socket.getPort());
                InputStream in=socket.getInputStream();
                OutputStream out=socket.getOutputStream();
                int ch=-1;
                while((ch=in.read())!=-1){
                    System.out.print((char)ch);
                }
                socket.close();//关闭
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
